package com.pingan.stat.reposys.general.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.pingan.common.core.property.Properties;
import com.pingan.common.util.ShellExecutor;
import com.pingan.setting.general.entity.GeneralStatSettingBean;
import com.pingan.setting.general.service.GeneralStatSettingService;
import com.pingan.stat.service.StatService;
import com.pingan.stat.service.TaskSubmitterService;

@Component
public class GeneralVisitFrequenceStatService implements StatService {

	@Properties(name = "reposys.general.output.path")
	private String outputPath;

	@Properties(name = "reposys.general.visit.frequence")
	private String generalVisitFrequenceShell;

	@Resource
	private ShellExecutor shellExecutor;

	@Resource
	private GeneralStatSettingService generalStatSettingService;

	@Resource
	private TaskSubmitterService taskSubmitterService;

	private static final Log log = LogFactory.getLog("hive");

	@Override
	public void dailyStat(Date date) {
		// TODO Auto-generated method stub
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String yyyyMMdd = sdf.format(date);
		String output = outputPath + "/" + yyyyMMdd;

		List<GeneralStatSettingBean> beans = generalStatSettingService
				.getGeneralStatSettingBeans();

		try {
			log.info("----------------->>>>>>>>>>>>>>>>>> stat visit frequence start....");
			taskSubmitterService.submit(beans, generalVisitFrequenceShell,
					yyyyMMdd, output);
			log.info("----------------->>>>>>>>>>>>>>>>>> stat visit frequence end");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
